﻿using System;
using System.Numerics;

class IntegerRepresentingArray

            // Write a method that adds two positive integer numbers represented as arrays of digits (each array element arr[i] contains a digit; 
            //the last digit is kept in arr[0]). Each of the numbers that will be added could have up to 10 000 digits.

{
    static void Main()
    {
        Console.Write("Enter the first positive integer: ");
        string firstInt = Console.ReadLine();                     
        Console.Write("Enter the second positive integer: ");
        string secondInt = Console.ReadLine();

        int[] firstArr = new int[Math.Max(firstInt.Length, secondInt.Length) + 1];   
        int[] secondArr = new int[Math.Max(firstInt.Length, secondInt.Length) + 1];  
        
        for (int i = firstInt.Length - 1; i >= 0; i--)                              
        {
            firstArr[firstInt.Length - i - 1] = byte.Parse(firstInt[i].ToString());
        }
        for (int i = secondInt.Length - 1; i >= 0; i--)
        {
            secondArr[secondInt.Length - i - 1] = byte.Parse(secondInt[i].ToString());
        }

        int[] firstReversed = ReverseArrays(firstArr);
        int[] secondReversed = ReverseArrays(secondArr);

        BigInteger sum = SumOfArrays(firstReversed, secondReversed);
        Console.WriteLine();
        Console.WriteLine("The sum of the two arrays is: {0}", sum);
    }

    static int[] ReverseArrays(int[] arr)
    {
        int[] reverse = new int[arr.Length];
        Array.Reverse(arr);

        for (int i = 0; i < arr.Length; i++)
        {
            reverse[i] = arr[i];
        }
            return reverse;
    }

    static BigInteger SumOfArrays(int[] arr1, int[] arr2)
    {
        BigInteger sum = 0;
        string num1 = "";
        string num2 = "";

        for (int i = 0; i < arr1.Length; i++)
        {
            num1 += arr1[i].ToString();
        }
        for (int i = 0; i < arr2.Length; i++)
        {
            num2 += arr2[i].ToString();
        }

        BigInteger first = BigInteger.Parse(num1);
        BigInteger second = BigInteger.Parse(num2);
        sum = first + second;

        return sum;
    }
}

